﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ReticleTrigger_for_DispayTextTip : MonoBehaviour {
	private VRReticleTriggerItem vrReticleTriggerItem;//处理凝视转圈进度条显示的类变量
	public  Text text_UI;//要显示的文本对象
	private void Awake ()
    {   
        //要保证对象有VRReticleTriggerItem脚本
        vrReticleTriggerItem = GetComponent<VRReticleTriggerItem> () ?? gameObject.AddComponent<VRReticleTriggerItem>() ;
        text_UI.enabled = false;//开始时是不显示文本的
    }

	//对象使能（激活）时调用
	private void OnEnable()
	{
		//订阅事件
		vrReticleTriggerItem.OnTrigger += HandleTrigger;
	}

	//对象不使能（不激活）时调用
	private void OnDisable()
    {   
        //去掉订阅的事件，与OnEnable的语句对应
        vrReticleTriggerItem.OnTrigger -= HandleTrigger;
	}

    //凝视触发（进度条满了）的事件代码
    void HandleTrigger ()
	{
        text_UI.enabled = true;  //显示文本提示
		StartCoroutine(DelayToDo()); //延时时间        
        this.GetComponent<Collider>().enabled = false;//设置当前对象的不可交互
	}
	IEnumerator DelayToDo()
	{
		yield return new WaitForSeconds(10);
        text_UI.enabled = false;  //关闭文本显示
		this.GetComponent<Collider>().enabled = true;//设置当前对象可交互
	}

}


